package com.fante.dubbo.manage.controller;

import com.fante.dubbo.manage.service.SysAdminService;
import com.fante.dubbo.manage.util.MD5Utils;
import com.fante.dubbo.manage.vo.LoginBean;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.thymeleaf.util.StringUtils;

/**
 *  用户的登录
 * @author liubao
 * @Date 2020/6/6
 */
@Controller
public class LoginController {


    @Autowired
    private SysAdminService sysAdminService;
    @PostMapping("/login")
    public String login(LoginBean loginBean) {
        String username = loginBean.getUsername();
        String password = loginBean.getPassword();
        String kaptcha = loginBean.getCode();
        if (StringUtils.isEmpty(username)) {
            return "用户名不能为空";
        }
        if (StringUtils.isEmpty(password)) {
            return "密码不能为空";
        }
        if (StringUtils.isEmpty(kaptcha)) {
            return "验证码不能为空";
        }
        String encodePassWord = sysAdminService.findByUserName(username).getPassword();
        String md5Encode = null;
        try{
             md5Encode =  MD5Utils.md5Encode(password);
        }catch (Exception e) {
            e.printStackTrace();
        }
        if(md5Encode.equals(encodePassWord)) {
            System.out.println("密码比对成功");
        }
        return "index";
    }
}
